﻿function $(obj) { return document.getElementById(obj) }
var maxWidth = null;
var isScroll = false;
var objID = null; //操作对象
var targetx = 200; //一次滚动距离
var dx;
var a = null;
function get_maxWidth() {
    maxWidth = $(objID).getElementsByTagName("ul")[0].getElementsByTagName("li").length * 140;
}
function moveLeft(DivID) {
    objID = DivID;
    get_maxWidth();
    var le = parseInt($(objID).scrollLeft);
    if (le > 200) {
        targetx = parseInt($(objID).scrollLeft) - 200;
    }
    else { targetx = parseInt($(objID).scrollLeft) - le - 1 }
    scLeft();
}
function scLeft() {
    dx = parseInt($(objID).scrollLeft) - targetx;
    $(objID).scrollLeft -= dx * .3;
    $("scroll").style.left = parseInt($(objID).scrollLeft) * (570 / (maxWidth - 600)) + "px";
    if (parseInt($("scroll").style.left) < 0) { $("scroll").style.left = 0 + "px" }
    if (parseInt($("scroll").style.left) > 570) { $("scroll").style.left = 570 + "px" }
    clearScroll = setTimeout(scLeft, 50);
    if (dx * .3 < 1) { clearTimeout(clearScroll) }
}
function moveRight(DivID) {
    objID = DivID;
    get_maxWidth();
    var le = parseInt($(objID).scrollLeft) + 200;
    var maxL = maxWidth - 600;
    if (le < maxL) {
        targetx = parseInt($(objID).scrollLeft) + 200;
    }
    else { targetx = maxL }
    scRight();
}
function scRight() {
    dx = targetx - parseInt($(objID).scrollLeft);
    $(objID).scrollLeft += dx * .3;
    $("scroll").style.left = parseInt($(objID).scrollLeft) * (573 / (maxWidth - 600)) + "px";
    if (parseInt($("scroll").style.left) < 0) { $("scroll").style.left = 0 + "px" }
    if (parseInt($("scroll").style.left) >= 570) { $("scroll").style.left = 570 + "px" }
    a = setTimeout(scRight, 50);
    if (dx * .3 < 1) { clearTimeout(a) }
}